package com.yunkeji.admin.controller.sys;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.SysCallSnapConfigVo;
import com.yunkeji.system.domain.bo.SysCallSnapConfigBo;
import com.yunkeji.system.service.ISysCallSnapConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 鉴黄配置
 *
 * @author yunkeji
 * @date 2024-09-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/CallSnapConfig")
public class SysCallSnapConfigController extends BaseController {

    private final ISysCallSnapConfigService iSysCallSnapConfigService;

    /** 查询鉴黄配置列表 */
    @SaCheckPermission("system:CallSnapConfig:list")
    @GetMapping("/list")
    public TableDataInfo<SysCallSnapConfigVo> list(SysCallSnapConfigBo bo, PageQuery pageQuery) {
        return iSysCallSnapConfigService.queryPageList(bo, pageQuery);
    }

    /** 导出鉴黄配置列表 */
    @SaCheckPermission("system:CallSnapConfig:export")
    @Log(title = "鉴黄配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysCallSnapConfigBo bo, HttpServletResponse response) {
        List<SysCallSnapConfigVo> list = iSysCallSnapConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "鉴黄配置", SysCallSnapConfigVo.class, response);
    }

    /**
     * 获取鉴黄配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:CallSnapConfig:query")
    @GetMapping("/{id}")
    public R<SysCallSnapConfigVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iSysCallSnapConfigService.queryById(id));
    }

    /** 新增鉴黄配置 */
    @SaCheckPermission("system:CallSnapConfig:add")
    @Log(title = "鉴黄配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysCallSnapConfigBo bo) {
        return toAjax(iSysCallSnapConfigService.insertByBo(bo));
    }

    /** 修改鉴黄配置 */
    @SaCheckPermission("system:CallSnapConfig:edit")
    @Log(title = "鉴黄配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCallSnapConfigBo bo) {
        return toAjax(iSysCallSnapConfigService.updateByBo(bo));
    }

    /**
     * 删除鉴黄配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:CallSnapConfig:remove")
    @Log(title = "鉴黄配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iSysCallSnapConfigService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
